home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
626-637
/
disk_629
/
rexxrmf
/
rexxrmf.lzh
/
videorental.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1992-03-14
|
18KB
|
571 lines
/* ---------------------------------------------------------------
Example illustrating use of 'linking' multiple files and indexes
This example 'links' three files together in an attempt to simulate
a 'relational' database for a fictious video rental store.
File 1 - videofile -
contains all videos in the store
primary key is a 'videonumber' which can occur
multiple times because of multiple copies of the
same video.
alternate keys are videorating
videocopynumber
renting customer number
hold for customer number
File 2 - customerfile -
contains names and addresses of registered
video patrons.
primary key is a unique 'customernumber'
alternate keys are customerlastname
customerbalance (if any)
File 3 - rentalfile -
rental history of each video by customer
primary key is 'videonumber'
alternate keys are customernumber
rentaldate
videcopynumber
I hope the relationship between the tree files is obvious.
The rentalfile links the videofile to the customer file.
* --------------------------------------------------------------- */
/* ------------------- Record Layout Strings --------------------- */
customerrecord = " custnumber custfirst custlast custaddr custcity custstate,
custzip custphone custareacode custdeposit custbalance"
videorecord = " videonum videotitle videocopy videorating videopudate,
videopuprice videosaleprice videoavail videohold videocust"
rentalrecord = " rentalcustnumber rentalvideonum rentalvideocopy rentaldate"
/* --- make library available --- */
x = addlib("RexxRMF.library",0,-30,0)
if exists("videofile") = 1 then
loadfile = 0
else
loadfile = 1
/* will allow duplicate keys in primary index for videos */
/* primary index is video number */
rmfvideos = open_rmf("videofile")
say "videofile " any_err(rmfvideos)
/* will NOT allow duplicate keys in primary index for customers */
/* primary index is customer number */
rmfcustomers = open_rmf("customerfile",1)
say "customersfile " any_err(rmfcustomers)
/* will allow duplicates in any index for rentals */
rmfrentals = open_rmf("rentalfile")
say "rentalfile " any_err(rmfrentals)
if loadfile = 1 then /* create data/index files */
do
r = loaddata()
if r = 0 then /* file creation failed */
do
if rmfvideos ~= '0000 0000'x then
call close_rmf(videofile,1)
if rmfcustomers ~= '0000 0000'x then
call close_rmf(rmfcustomers,1)
if rmfrentals ~= '0000 0000'x then
call close_rmf(rmfrentals,1)
if exists('videofile') then
delete 'videofile'
if exists('customerfile') then
delete 'customerfile'
if exists('rentalfile') then
delete 'rentalfile'
if exists('videofile.rmfindex') then
delete 'videofile.rmfindex'
if exists('customerfile.rmfindex') then
delete 'customerfile.rmfindex'
if exists('rentalfile.rmfindex') then
delete 'rentalfile.rmfindex'
say " ... BIG ERROR !!! Unable to create data/index files ... "
exit
end
end
/* open a console, uncomment the open() for whichever is required for you */
/* use this if running WShell/conman1.3 under ADOS 1.3 */
/* x = open(outwin,"CON:0/0/640/200//") */
/* use this if running WShell/conman1.3 under ADOS 2.04 */
/* x = open(outwin,"CON:0/0/640/200//r") */
/* use this if running WShell2.0/DisplayHandler under ADOS 2.04 */
x = open(outwin,"CON:0/0/640/200//SMART")
/* just some console escape sequences */
eraseconsolescreen = '9b48 9b4a'x
offsetwrites = '9b39 3978'x
offsettop = '9b39 3979'x
resettop = '9b79'x
resetwrites = '9b78'x
EOD = '9b4a'x
EOL = '9b4b'x
CURSORUP = '9b46'x
CURSORDOWN = '9b45'x
/* --------- Our Menu --------- */
do forever
zout = writech(outwin,rowcol(1,1)EOD)
zout = writeln(outwin,'0a'x copies(' ',16)color(2,1)"Your Get Rich Quick Video Rental Store" color(1,0) '0a'x)
zout = writeln(outwin,'0a'x copies(' ',28) color(1,0)"M E N U"'0a'x'0a'x)
zout = writeln(outwin,'0a'x copies(' ',24) color(1,0)"1)." color(3,0)" Customer Inquiry")
zout = writeln(outwin,'0a'x copies(' ',24) color(1,0)"2)." color(3,0)" Video Inquiry")
zout = writeln(outwin,'0a'x copies(' ',24) color(1,0)"X)." color(3,0)" Enter" color(2,0)"X"color(3,0)" to exit")
zout = writeln(outwin,'0a'x'0a'x'0a'x)
zout = writech(outwin, copies(' ',23) color(1,0)"Enter Option 1 or 2 or X: ")
op = readln(outwin)
select
when op = 1 then /* our CUSTOMER INQUIRY */
do
do forever
zout = writech(outwin,rowcol(1,1)EOD)
x = customerhistory()
if x > 50 then leave
end
end
when op = 2 then /* our VIDEO INQUIRY */
do
zout = writech(outwin,rowcol(1,1)EOD)
vx = videohistory(0)
do forever
vx = videohistory(vx)
if vx > 99999 then leave
if vx = 0 then leave
end
end
when op = 'X' then leave
when op = 'x' then leave
otherwise nop
end
end
/* ---------- Save Files --------- */
call writech(outwin,rowcol(1,1)EOD)
call writech(outwin,rowcol(12,32)color(2,1)"Saving Video Data"color(1,0))
x = close_rmf(rmfvideos)
call writech(outwin,rowcol(1,1)EOD)
call writech(outwin,rowcol(12,32)color(2,1)"Saving Customer Data"color(1,0))
x = close_rmf(rmfcustomers)
call writech(outwin,rowcol(1,1)EOD)
call writech(outwin,rowcol(12,32)color(2,1)"Saving Rental Data"color(1,0))
x = close_rmf(rmfrentals)
x = close(outwin)
exit
/*-------------------------------------------------------------------------*
*- -*
*-------------------------------------------------------------------------*/
customerhistory:
zout = writech(outwin,'0a'x "Enter Customer Name or Number ?")
customer = readln(outwin)
customer = strip(customer)
if customer = '' then return 99
if datatype(customer) = 'NUM' then /* entered a customer number */
do
l = length(customer)
if l > 4 then
do
zout = writeln(outwin,"Invalid customer number, must be 4digits or less")
return 0
end
customer = (copies('0',(4-l)) || customer) /* append leading zeros */
end
else /* else if not numeric assume entered a customer last name */
customer = upper(customer)
/* READ THE CUSTOMER FILE */
/* the primary index (0) indexes on customer number */
/* the first alternate (1) indexes on customer last name */
if datatype(customer) = 'NUM' then /* READ BY CUSTOMER NUMBER */
x = read_rmf_record(rmfcustomers,0,customerrecord,customer,'K')
else /* READ BY CUSTOMER LAST NAME */
x = read_rmf_record(rmfcustomers,1,customerrecord,customer,'K')
if x = 0 then
do
zout = writeln(outwin,'0a'x'0a'x"Customer:" customer "NOT FOUND")
zout = writech(outwin,'0a'x'0a'x"Press Return to Continue ...")
x = readln(outwin)
return 0
end
/* DISPLAY CUSTOMER RECORD */
zout = writeln(outwin,'0a'x color(3,0)"Cust#:" color(2,0)custnumber)
zout = writeln(outwin,color(3,0)" Name :" color(2,0)custfirst custlast )
zout = writeln(outwin,color(3,0)" Addrs:" color(2,0)custaddr )
zout = writeln(outwin,color(3,0)" City :" color(2,0)custcity custstate custzip )
zout = writeln(outwin,color(3,0)" Phone:" color(2,0)'('custareacode')' custphone )
zout = writeln(outwin,rowcol(5,40)color(3,0)"Deposit On File:" color(2,0)custdeposit )
zout = writeln(outwin,rowcol(6,40)color(3,0)"Balance Due:" color(2,0)custbalance)
zout = writeln(outwin,rowcol(9,1))
zout = writech(outwin,offsetwrites)
zout = writeln(outwin,color(2,1)"Film# CP Rented Title"copies(' ',23)"Rating"color(1,0))
zout = writech(outwin,null())
zout = writech(outwin,offsettop)
/* READ THE RENTAL FILE FOR THIS CUSTOMER */
x = read_rmf_record(rmfrentals,1,rentalrecord,custnumber,'K')
if x = 0 then zout = writeln(outwin, "No rental records found")
displayed = 0
do while x = 1 /* the NEXT_RMF_RECORD below will set x to zero */
/* READ THE VIDEO FILE TO GET VIDEO INFO */
y = read_rmf_record(rmfvideos,0,videorecord,rentalvideonum,'K')
if y = 1 then
do
title = substr(videotitle,1,32," ")
zout = writeln(outwin, rentalvideonum rentalvideocopy rentaldate title videorating)
displayed = displayed + 1
end
if displayed = 9 then
do
x = writech(outwin,'0a'x'0a'x"Press Return to Continue ...")
x = readln(outwin)
x = writech(outwin,'9b46 9b4b'x) /* move up and erase line */
x = writech(outwin,'9b46'x) /* to effect scrolling */
x = writech(outwin,'9b46'x)
displayed = 0
end
/* get the next rental record for this customer */
x = next_rmf_record(rmfrentals,1,rentalrecord)
end
x = writech(outwin,'0a'x"**** **** End of List **** ****")
x = writech(outwin,'0a'x'0a'x"Press Return to Continue ...")
x = readln(outwin)
zout = writech(outwin,resetwrites)
zout = writech(outwin,resettop)
return 1
/*-------------------------------------------------------------------------*
*- -*
*-------------------------------------------------------------------------*/
videohistory:
parse arg vidnumber
if vidnumber = 0 then
do
/* GET LIST OF VIDEO NUMBERS */
vidnode = find_pos(rmfvideos,0,1) /* find first record in index */
zout = writech(outwin,copies(' ',29) color(2,1)"Video Numbers" color(1,0) '0a'x " ")
displayed = 0
linecnt = 0
do while vidnode ~= '0000 0000'x /* vidnode is a POINTER to node in the tree */
thevideonumberis = " " || key_value(vidnode)
zout = writech(outwin,(color(2,1) || thevideonumberis || color(1,0)) )
displayed = displayed + 1
if displayed > 7 then
do
displayed = 0
zout = writech(outwin,(color(2,1) || " " || '0a'x || color(1,0) || " ") )
linecnt = linecnt + 1
if linecnt > 8 then leave
end
vidnode = next_unique(rmfvideos,0) /* low-level functions dont do any I/O */
end
vidnumber = get_a_video_number()
end /* if vidnumber = 0 */
zout = writech(outwin,color(1,0))
if vidnumber > 99999 then return 999999
if vidnumber = 0 then return 999999
/* READ THE VIDEO FILE TO GET VIDEO INFO */
do forever
x = read_rmf_record(rmfvideos,0,videorecord,vidnumber,'K')
if x = 1 then leave /* found video in file */
zout = writeln(outwin,rowcol(12,1)"Video Number:" vidnumber "NOT FOUND")
zout = writech(outwin, rowcol(21,1))
zout = writech(outwin,"Press Return to Continue ...")
zin = readln(outwin)
vidnumber = get_a_video_number()
if vidnumber > 99999 then return 999999
if vidnumber = 0 then return 999999
end
currentcust = ''
currenthold = ''
videocust = random(1,100) /* generate a customer number */
if videocust > 0 then /* READ CUSTOMER FILE FOR CURRENT RENTER */
do
videocust = copies('0',(4-length(videocust))) || videocust
custfound = read_rmf_record(rmfcustomers,0,customerrecord,videocust,'K')
if custfound then
currentcust = custfirst custlast
else
videocust = '0000'
end
videohold = random(1,100) /* generate a customer number */
if videohold = videocust then
videohold = 0
if videohold > 0 then /* READ CUSTOMER FILE FOR, HOLD FOR CUSTOMER */
do
videohold = copies('0',(4-length(videohold))) || videohold
holdfound = read_rmf_record(rmfcustomers,0,customerrecord,videohold,'K')
if holdfound then
currenthold = custfirst custlast
else
videohold = '0000'
end
/* HOW MANY COPIES WE GOT */
count = key_count(rmfvideos,0,vidnumber,'K')
zout = writeln(outwin,rowcol(12,1)" Video#:" videonum " Number of copies:" count)
title = substr(videotitle,1,32,' ')
zout = writech(outwin,color(3,0)" Title :")
zout = writeln(outwin,color(2,0)title color(3,0) "Copy#:" color(2,0)videocopy color(3,0)"Rating:" color(2,0)videorating)
zout = writeln(outwin,color(3,0)" Date Purchased:"color(2,0)videopudate)
zout = writeln(outwin,color(3,0)" Purchase Price:"color(2,0)videopuprice)
zout = writeln(outwin,color(3,0)" Sale Price :"color(2,0)videosaleprice)
zout = writeln(outwin,color(3,0)" Available :"color(2,0)videoavail)
zout = writeln(outwin,color(3,0)" Hold For :"color(2,0)videohold color(3,0)" Name:" color(2,0)currenthold)
zout = writeln(outwin,color(3,0)" Current Renter:"color(2,0)videocust color(3,0)" Name:" color(2,0)currentcust)
zout = writech(outwin, rowcol(21,1))
x = writech(outwin, color(1,0) "Press Return to Continue ...")
x = readln(outwin)
return get_a_video_number()
/*-------------------------------------------------------------------------*
*- -*
*-------------------------------------------------------------------------*/
get_a_video_number:
do forever
zout = writech(outwin,rowcol(12,1)EOD)
zout = writech(outwin,rowcol(21,1) color(1,0)"Enter Video Number ?")
vidn = readln(outwin)
if vidn = '' then leave
if datatype(vidnumber) = 'NUM' then
do
vl = length(vidn)
if vl > 5 then
do
zout = writech(outwin, color(1,0) rowcol(12,1) EOD)
zout = writeln(outwin,"Invalid Video Number, must be 5digits or less")
zout = writech(outwin, rowcol(21,1))
zout = writech(outwin,"Press Return to Continue ...")
zin = readln(outwin)
end
vidn = (copies('0',(5-vl)) || vidn) /* append leading zeros */
if vidn = '00000' then return 999999
return vidn
end
else
do
zout = writeln(outwin,"Invalid Video Number, must be Numeric")
zout = writech(outwin, rowcol(21,1))
zout = writech(outwin,"Press Return to Continue ...")
zin = readln(outwin)
end
end
return 999999
/*-------------------------------------------------------------------------*
*- -*
*-------------------------------------------------------------------------*/
rowcol:
parse arg row,col
outb = '9b'x || row || ';' || col || 'H'
return outb
/*-------------------------------------------------------------------------*
*- -*
*-------------------------------------------------------------------------*/
color:
parse arg fg,bg
outb = '9b'x || '0;3' || fg || ';4' || bg || 'm'
return outb
/*-------------------------------------------------------------------------*
*- -*
*- Load RMF files with data -*
*- This is only called when the rmf files do not exists -*
*- -*
*-------------------------------------------------------------------------*/
loaddata:
x = open(viddata,"viddata",'R')
if x = 0 then
do
zout = writeln(outwin, "could not open video data file")
return 0
end
x = open(rentdata,"rentdata",'R')
if x = 0 then
do
zout = writeln(outwin, "could not open rental data file")
return 0
end
x = open(custdata,"custdata",'R')
if x = 0 then
do
zout = writeln(outwin, "could not open customer data file")
return 0
end
/* LOAD CUSTOMER DATA */
do forever
cdata = readln(custdata)
if eof(custdata) = 1 then leave
if substr(cdata,1,1) = '#' then iterate
parse var cdata custnumber ',' custfirst ',' custlast ',' custaddr ',' ,
custcity ',' custstate ',' custzip ',' custphone ',' ,
custareacode ',' custdeposit ',' custbalance
lastname = upper(custlast)
if custbalance > 0 then
x = write_rmf_record(rmfcustomers,customerrecord,custnumber,1,lastname)
else
x = write_rmf_record(rmfcustomers,customerrecord,custnumber,1,lastname,2,custbalance)
if x = 0 then
do
say "Write Failed " any_err(rmfcustomers)
say custfirst custlast custnumber
end
end
/* LOAD VIDEO DATA */
do forever
vdata = readln(viddata)
if eof(viddata) = 1 then leave
if substr(vdata,1,1) = '#' then iterate
parse var vdata videonum ',' videotitle ',' videocopy ',' videorating ',' ,
videopudate ',' videopuprice ',' videosaleprice ',' ,
videoavail ',' videohold ',' videocust
filmcopy = strip((videonum || videocopy))
if videoavail = 'Y' then
x = write_rmf_record(rmfvideos,videorecord,videonum,1,videorating,4,filmcopy)
else
if videohold > 0 then /* hold video for this customer */
x = write_rmf_record(rmfvideos,videorecord,videonum,1,videorating,2,videohold,4,filmcopy)
else
if videocust > 0 then /* this customer has it */
x = write_rmf_record(rmfvideos,videorecord,videonum,1,videorating,3,videocust,4,filmcopy)
if x = 0 then
do
say "Write failed" any_err(rmfvideos)
say videonum videocopy
end
end
/* LOAD RENTAL DATA */
do forever
rdata = readln(rentdata)
if eof(rentdata) = 1 then leave
if substr(rdata,1,1) = '#' then iterate
parse var rdata rentalcustnumber ',' rentalvideonum ',' rentalvideocopy ',' rentaldate
filmcopy = strip( (rentalvideonum || rentalvideocopy) )
x = write_rmf_record(rmfrentals,rentalrecord,rentalvideonum,1,rentalcustnumber,2,rentaldate,3,filmcopy)
end
x = close(viddata)
x = close(rentdata)
x = close(custdata)
return 1